<template>
	<view class="paper">
		<!-- 操作菜单 -->
		<paper-menu :isShowMenu="isShowMenu" @addfriend="addfriend" @clear="clear" @hidePopup="hidePopup"></paper-menu>
		<!-- 小纸条列表 -->
		<block v-for="(item,index) in list" :key="index">
			<paper-list :item="item" :index="index"></paper-list>
		</block>
		<!-- 上拉加载 -->
		<load-more :loadtext="loadtext"></load-more>


	</view>
</template>

<script>
	import paperList from "../../components/paper/paper-list.vue"
	import loadMore from "../../components/common/load-more.vue"
	import paperMenu from "../../components/paper/paper-menu.vue"
	export default {
		data() {
			return {
				loadtext: "上拉加载更多",
				isShowMenu: false,
				list: [{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 1
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 999
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
					{
						userpic: "../../static/image/userpic/12.jpg",
						username: "昵称",
						timer: "10:21",
						message: "我是信息",
						unread: 3
					},
				]
			};
		},
		methods: {
			getData() {
				console.log("请求数据")
			},
			loadMore() {
				if (this.loadtext !== "上拉加载更多") {
					return
				}
				let obj = {
					userpic: "../../static/image/userpic/12.jpg",
					username: "昵称",
					timer: "10:21",
					message: "我是信息",
					unread: 3
				}
				// 修改状态
				this.loadtext = "拼命加载中. . ."
				setTimeout(() => {
					this.list.push(obj)
					this.loadtext = "上拉加载更多"
					// this.loadtext = "人家是有底线的 Ծ ‸ Ծ"
				}, 1000)
			},
			
			addfriend() {
				console.log("添加糗友")
				this.hidePopup()
			},
			clear() {
				console.log("清除")
				this.hidePopup()
			},
			hidePopup() {
				this.isShowMenu = false
			},
			showPopup(){
				this.isShowMenu = true
			}
		},
		components: {
			paperList,
			loadMore,
			paperMenu
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.getData()
			uni.stopPullDownRefresh()
		},
		// 上拉加载
		onReachBottom() {
			this.loadMore()
		},
		// 监听原生按钮事件
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				this.$Router.push({name: 'user-list'})
				this.hidePopup()
			}
			if (e.index === 1 && !this.isShowMenu) {
				this.showPopup()
			} else {
				this.hidePopup()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.paper {
		padding: 0 20upx;
	}
</style>
